package com.atguigu.classroom.wechat.controller;

import com.atguigu.classroom.result.Result;
import com.atguigu.classroom.wechat.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "微信公众号普通消息接口")
@RestController
@RequestMapping("/api/wechat/message/")
public class MessageController {
    @Autowired
    private MessageService messageService;
    @ApiOperation("验证消息的确来自微信服务器")
    @GetMapping
    public String verifyToken(HttpServletRequest request){
        return messageService.verifyToken(request);
    }
    @ApiOperation("接收微信服务器发送来的消息")
    @PostMapping
    public String receiveMessage(HttpServletRequest request){
        return messageService.receiveMessage(request);
    }
    @ApiOperation("公众号模板消息")
    @GetMapping("/pushPayMessage")
    public Result pushPayMessage() throws WxErrorException {
        messageService.pushPayMessage(1L);
        return Result.ok(null);
    }
}
